﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Data;

#endregion

namespace BesAsm.MasterData.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="StatusProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class StatusProviderBaseCore : EntityProviderBase<BesAsm.MasterData.Entities.Status, BesAsm.MasterData.Entities.StatusKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, BesAsm.MasterData.Entities.StatusKey key)
		{
			return Delete(transactionManager, key.StatusId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_statusId">Primary key, status ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.String _statusId)
		{
			return Delete(null, _statusId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_statusId">Primary key, status ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.String _statusId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override BesAsm.MasterData.Entities.Status Get(TransactionManager transactionManager, BesAsm.MasterData.Entities.StatusKey key, int start, int pageLength)
		{
			return GetByStatusId(transactionManager, key.StatusId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_STATUSES index.
		/// </summary>
		/// <param name="_statusId">Primary key, status ID</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Status"/> class.</returns>
		public BesAsm.MasterData.Entities.Status GetByStatusId(System.String _statusId)
		{
			int count = -1;
			return GetByStatusId(null,_statusId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_STATUSES index.
		/// </summary>
		/// <param name="_statusId">Primary key, status ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Status"/> class.</returns>
		public BesAsm.MasterData.Entities.Status GetByStatusId(System.String _statusId, int start, int pageLength)
		{
			int count = -1;
			return GetByStatusId(null, _statusId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_STATUSES index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_statusId">Primary key, status ID</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Status"/> class.</returns>
		public BesAsm.MasterData.Entities.Status GetByStatusId(TransactionManager transactionManager, System.String _statusId)
		{
			int count = -1;
			return GetByStatusId(transactionManager, _statusId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_STATUSES index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_statusId">Primary key, status ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Status"/> class.</returns>
		public BesAsm.MasterData.Entities.Status GetByStatusId(TransactionManager transactionManager, System.String _statusId, int start, int pageLength)
		{
			int count = -1;
			return GetByStatusId(transactionManager, _statusId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_STATUSES index.
		/// </summary>
		/// <param name="_statusId">Primary key, status ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Status"/> class.</returns>
		public BesAsm.MasterData.Entities.Status GetByStatusId(System.String _statusId, int start, int pageLength, out int count)
		{
			return GetByStatusId(null, _statusId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_STATUSES index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_statusId">Primary key, status ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.Status"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.Status GetByStatusId(TransactionManager transactionManager, System.String _statusId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;Status&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;Status&gt;"/></returns>
		public static TList<Status> Fill(IDataReader reader, TList<Status> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				BesAsm.MasterData.Entities.Status c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("Status")
					.Append("|").Append((System.String)reader[((int)StatusColumn.StatusId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<Status>(
					key.ToString(), // EntityTrackingKey
					"Status",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new BesAsm.MasterData.Entities.Status();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.StatusId = (System.String)reader[((int)StatusColumn.StatusId - 1)];
					c.OriginalStatusId = c.StatusId;
					c.Description = (reader.IsDBNull(((int)StatusColumn.Description - 1)))?null:(System.String)reader[((int)StatusColumn.Description - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.Status"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.Status"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, BesAsm.MasterData.Entities.Status entity)
		{
			if (!reader.Read()) return;
			
			entity.StatusId = (System.String)reader[((int)StatusColumn.StatusId - 1)];
			entity.OriginalStatusId = (System.String)reader["status_id"];
			entity.Description = (reader.IsDBNull(((int)StatusColumn.Description - 1)))?null:(System.String)reader[((int)StatusColumn.Description - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.Status"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.Status"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, BesAsm.MasterData.Entities.Status entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.StatusId = (System.String)dataRow["status_id"];
			entity.OriginalStatusId = (System.String)dataRow["status_id"];
			entity.Description = Convert.IsDBNull(dataRow["description"]) ? null : (System.String)dataRow["description"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.Status"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.Status Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, BesAsm.MasterData.Entities.Status entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByStatusId methods when available
			
			#region RoofTargetCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<RoofTarget>|RoofTargetCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'RoofTargetCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.RoofTargetCollection = DataRepository.RoofTargetProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.RoofTargetCollection.Count > 0)
				{
					deepHandles.Add("RoofTargetCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<RoofTarget>) DataRepository.RoofTargetProvider.DeepLoad,
						new object[] { transactionManager, entity.RoofTargetCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region CrossSectionDatumCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<CrossSectionDatum>|CrossSectionDatumCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CrossSectionDatumCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.CrossSectionDatumCollection = DataRepository.CrossSectionDatumProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.CrossSectionDatumCollection.Count > 0)
				{
					deepHandles.Add("CrossSectionDatumCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<CrossSectionDatum>) DataRepository.CrossSectionDatumProvider.DeepLoad,
						new object[] { transactionManager, entity.CrossSectionDatumCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PumpCurveCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PumpCurve>|PumpCurveCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PumpCurveCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PumpCurveCollection = DataRepository.PumpCurveProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.PumpCurveCollection.Count > 0)
				{
					deepHandles.Add("PumpCurveCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PumpCurve>) DataRepository.PumpCurveProvider.DeepLoad,
						new object[] { transactionManager, entity.PumpCurveCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region SscCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Ssc>|SscCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'SscCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.SscCollection = DataRepository.SscProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.SscCollection.Count > 0)
				{
					deepHandles.Add("SscCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Ssc>) DataRepository.SscProvider.DeepLoad,
						new object[] { transactionManager, entity.SscCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region ParkingTargetCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<ParkingTarget>|ParkingTargetCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'ParkingTargetCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.ParkingTargetCollection = DataRepository.ParkingTargetProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.ParkingTargetCollection.Count > 0)
				{
					deepHandles.Add("ParkingTargetCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<ParkingTarget>) DataRepository.ParkingTargetProvider.DeepLoad,
						new object[] { transactionManager, entity.ParkingTargetCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region FixedFloorElevationCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<FixedFloorElevation>|FixedFloorElevationCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'FixedFloorElevationCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.FixedFloorElevationCollection = DataRepository.FixedFloorElevationProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.FixedFloorElevationCollection.Count > 0)
				{
					deepHandles.Add("FixedFloorElevationCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<FixedFloorElevation>) DataRepository.FixedFloorElevationProvider.DeepLoad,
						new object[] { transactionManager, entity.FixedFloorElevationCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region NodeCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Node>|NodeCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'NodeCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.NodeCollection = DataRepository.NodeProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.NodeCollection.Count > 0)
				{
					deepHandles.Add("NodeCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Node>) DataRepository.NodeProvider.DeepLoad,
						new object[] { transactionManager, entity.NodeCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region CrossSectionCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<CrossSection>|CrossSectionCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CrossSectionCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.CrossSectionCollection = DataRepository.CrossSectionProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.CrossSectionCollection.Count > 0)
				{
					deepHandles.Add("CrossSectionCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<CrossSection>) DataRepository.CrossSectionProvider.DeepLoad,
						new object[] { transactionManager, entity.CrossSectionCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region AsmZoningCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<AsmZoning>|AsmZoningCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'AsmZoningCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.AsmZoningCollection = DataRepository.AsmZoningProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.AsmZoningCollection.Count > 0)
				{
					deepHandles.Add("AsmZoningCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<AsmZoning>) DataRepository.AsmZoningProvider.DeepLoad,
						new object[] { transactionManager, entity.AsmZoningCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PumpCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Pump>|PumpCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PumpCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PumpCollection = DataRepository.PumpProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.PumpCollection.Count > 0)
				{
					deepHandles.Add("PumpCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Pump>) DataRepository.PumpProvider.DeepLoad,
						new object[] { transactionManager, entity.PumpCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region DscCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Dsc>|DscCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DscCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.DscCollection = DataRepository.DscProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.DscCollection.Count > 0)
				{
					deepHandles.Add("DscCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Dsc>) DataRepository.DscProvider.DeepLoad,
						new object[] { transactionManager, entity.DscCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region StormCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Storm>|StormCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'StormCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.StormCollection = DataRepository.StormProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.StormCollection.Count > 0)
				{
					deepHandles.Add("StormCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Storm>) DataRepository.StormProvider.DeepLoad,
						new object[] { transactionManager, entity.StormCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PipeShapeCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PipeShape>|PipeShapeCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PipeShapeCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PipeShapeCollection = DataRepository.PipeShapeProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.PipeShapeCollection.Count > 0)
				{
					deepHandles.Add("PipeShapeCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PipeShape>) DataRepository.PipeShapeProvider.DeepLoad,
						new object[] { transactionManager, entity.PipeShapeCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region OrificeCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Orifice>|OrificeCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'OrificeCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.OrificeCollection = DataRepository.OrificeProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.OrificeCollection.Count > 0)
				{
					deepHandles.Add("OrificeCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Orifice>) DataRepository.OrificeProvider.DeepLoad,
						new object[] { transactionManager, entity.OrificeCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region StreetTargetCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<StreetTarget>|StreetTargetCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'StreetTargetCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.StreetTargetCollection = DataRepository.StreetTargetProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.StreetTargetCollection.Count > 0)
				{
					deepHandles.Add("StreetTargetCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<StreetTarget>) DataRepository.StreetTargetProvider.DeepLoad,
						new object[] { transactionManager, entity.StreetTargetCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PipeShapeDatumCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PipeShapeDatum>|PipeShapeDatumCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PipeShapeDatumCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PipeShapeDatumCollection = DataRepository.PipeShapeDatumProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.PipeShapeDatumCollection.Count > 0)
				{
					deepHandles.Add("PipeShapeDatumCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PipeShapeDatum>) DataRepository.PipeShapeDatumProvider.DeepLoad,
						new object[] { transactionManager, entity.PipeShapeDatumCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region SanPatternCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<SanPattern>|SanPatternCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'SanPatternCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.SanPatternCollection = DataRepository.SanPatternProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.SanPatternCollection.Count > 0)
				{
					deepHandles.Add("SanPatternCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<SanPattern>) DataRepository.SanPatternProvider.DeepLoad,
						new object[] { transactionManager, entity.SanPatternCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region WeirCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Weir>|WeirCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'WeirCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.WeirCollection = DataRepository.WeirProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.WeirCollection.Count > 0)
				{
					deepHandles.Add("WeirCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Weir>) DataRepository.WeirProvider.DeepLoad,
						new object[] { transactionManager, entity.WeirCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region SpecialLinkCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<SpecialLink>|SpecialLinkCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'SpecialLinkCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.SpecialLinkCollection = DataRepository.SpecialLinkProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.SpecialLinkCollection.Count > 0)
				{
					deepHandles.Add("SpecialLinkCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<SpecialLink>) DataRepository.SpecialLinkProvider.DeepLoad,
						new object[] { transactionManager, entity.SpecialLinkCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region SpecialLinkDatumCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<SpecialLinkDatum>|SpecialLinkDatumCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'SpecialLinkDatumCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.SpecialLinkDatumCollection = DataRepository.SpecialLinkDatumProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.SpecialLinkDatumCollection.Count > 0)
				{
					deepHandles.Add("SpecialLinkDatumCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<SpecialLinkDatum>) DataRepository.SpecialLinkDatumProvider.DeepLoad,
						new object[] { transactionManager, entity.SpecialLinkDatumCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PipeConflictCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PipeConflict>|PipeConflictCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PipeConflictCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PipeConflictCollection = DataRepository.PipeConflictProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.PipeConflictCollection.Count > 0)
				{
					deepHandles.Add("PipeConflictCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PipeConflict>) DataRepository.PipeConflictProvider.DeepLoad,
						new object[] { transactionManager, entity.PipeConflictCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region LinkCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Link>|LinkCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'LinkCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.LinkCollection = DataRepository.LinkProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.LinkCollection.Count > 0)
				{
					deepHandles.Add("LinkCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Link>) DataRepository.LinkProvider.DeepLoad,
						new object[] { transactionManager, entity.LinkCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region IcNodeRedirectorCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<IcNodeRedirector>|IcNodeRedirectorCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IcNodeRedirectorCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.IcNodeRedirectorCollection = DataRepository.IcNodeRedirectorProvider.GetByStatus(transactionManager, entity.StatusId);

				if (deep && entity.IcNodeRedirectorCollection.Count > 0)
				{
					deepHandles.Add("IcNodeRedirectorCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<IcNodeRedirector>) DataRepository.IcNodeRedirectorProvider.DeepLoad,
						new object[] { transactionManager, entity.IcNodeRedirectorCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the BesAsm.MasterData.Entities.Status object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">BesAsm.MasterData.Entities.Status instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.Status Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, BesAsm.MasterData.Entities.Status entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
	
			#region List<RoofTarget>
				if (CanDeepSave(entity.RoofTargetCollection, "List<RoofTarget>|RoofTargetCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(RoofTarget child in entity.RoofTargetCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.RoofTargetCollection.Count > 0 || entity.RoofTargetCollection.DeletedItems.Count > 0)
					{
						//DataRepository.RoofTargetProvider.Save(transactionManager, entity.RoofTargetCollection);
						
						deepHandles.Add("RoofTargetCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< RoofTarget >) DataRepository.RoofTargetProvider.DeepSave,
							new object[] { transactionManager, entity.RoofTargetCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<CrossSectionDatum>
				if (CanDeepSave(entity.CrossSectionDatumCollection, "List<CrossSectionDatum>|CrossSectionDatumCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(CrossSectionDatum child in entity.CrossSectionDatumCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.CrossSectionDatumCollection.Count > 0 || entity.CrossSectionDatumCollection.DeletedItems.Count > 0)
					{
						//DataRepository.CrossSectionDatumProvider.Save(transactionManager, entity.CrossSectionDatumCollection);
						
						deepHandles.Add("CrossSectionDatumCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< CrossSectionDatum >) DataRepository.CrossSectionDatumProvider.DeepSave,
							new object[] { transactionManager, entity.CrossSectionDatumCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<PumpCurve>
				if (CanDeepSave(entity.PumpCurveCollection, "List<PumpCurve>|PumpCurveCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PumpCurve child in entity.PumpCurveCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.PumpCurveCollection.Count > 0 || entity.PumpCurveCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PumpCurveProvider.Save(transactionManager, entity.PumpCurveCollection);
						
						deepHandles.Add("PumpCurveCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PumpCurve >) DataRepository.PumpCurveProvider.DeepSave,
							new object[] { transactionManager, entity.PumpCurveCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<Ssc>
				if (CanDeepSave(entity.SscCollection, "List<Ssc>|SscCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Ssc child in entity.SscCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.SscCollection.Count > 0 || entity.SscCollection.DeletedItems.Count > 0)
					{
						//DataRepository.SscProvider.Save(transactionManager, entity.SscCollection);
						
						deepHandles.Add("SscCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Ssc >) DataRepository.SscProvider.DeepSave,
							new object[] { transactionManager, entity.SscCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<ParkingTarget>
				if (CanDeepSave(entity.ParkingTargetCollection, "List<ParkingTarget>|ParkingTargetCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(ParkingTarget child in entity.ParkingTargetCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.ParkingTargetCollection.Count > 0 || entity.ParkingTargetCollection.DeletedItems.Count > 0)
					{
						//DataRepository.ParkingTargetProvider.Save(transactionManager, entity.ParkingTargetCollection);
						
						deepHandles.Add("ParkingTargetCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< ParkingTarget >) DataRepository.ParkingTargetProvider.DeepSave,
							new object[] { transactionManager, entity.ParkingTargetCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<FixedFloorElevation>
				if (CanDeepSave(entity.FixedFloorElevationCollection, "List<FixedFloorElevation>|FixedFloorElevationCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(FixedFloorElevation child in entity.FixedFloorElevationCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.FixedFloorElevationCollection.Count > 0 || entity.FixedFloorElevationCollection.DeletedItems.Count > 0)
					{
						//DataRepository.FixedFloorElevationProvider.Save(transactionManager, entity.FixedFloorElevationCollection);
						
						deepHandles.Add("FixedFloorElevationCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< FixedFloorElevation >) DataRepository.FixedFloorElevationProvider.DeepSave,
							new object[] { transactionManager, entity.FixedFloorElevationCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<Node>
				if (CanDeepSave(entity.NodeCollection, "List<Node>|NodeCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Node child in entity.NodeCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.NodeCollection.Count > 0 || entity.NodeCollection.DeletedItems.Count > 0)
					{
						//DataRepository.NodeProvider.Save(transactionManager, entity.NodeCollection);
						
						deepHandles.Add("NodeCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Node >) DataRepository.NodeProvider.DeepSave,
							new object[] { transactionManager, entity.NodeCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<CrossSection>
				if (CanDeepSave(entity.CrossSectionCollection, "List<CrossSection>|CrossSectionCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(CrossSection child in entity.CrossSectionCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.CrossSectionCollection.Count > 0 || entity.CrossSectionCollection.DeletedItems.Count > 0)
					{
						//DataRepository.CrossSectionProvider.Save(transactionManager, entity.CrossSectionCollection);
						
						deepHandles.Add("CrossSectionCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< CrossSection >) DataRepository.CrossSectionProvider.DeepSave,
							new object[] { transactionManager, entity.CrossSectionCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<AsmZoning>
				if (CanDeepSave(entity.AsmZoningCollection, "List<AsmZoning>|AsmZoningCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(AsmZoning child in entity.AsmZoningCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.AsmZoningCollection.Count > 0 || entity.AsmZoningCollection.DeletedItems.Count > 0)
					{
						//DataRepository.AsmZoningProvider.Save(transactionManager, entity.AsmZoningCollection);
						
						deepHandles.Add("AsmZoningCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< AsmZoning >) DataRepository.AsmZoningProvider.DeepSave,
							new object[] { transactionManager, entity.AsmZoningCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<Pump>
				if (CanDeepSave(entity.PumpCollection, "List<Pump>|PumpCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Pump child in entity.PumpCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.PumpCollection.Count > 0 || entity.PumpCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PumpProvider.Save(transactionManager, entity.PumpCollection);
						
						deepHandles.Add("PumpCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Pump >) DataRepository.PumpProvider.DeepSave,
							new object[] { transactionManager, entity.PumpCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<Dsc>
				if (CanDeepSave(entity.DscCollection, "List<Dsc>|DscCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Dsc child in entity.DscCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.DscCollection.Count > 0 || entity.DscCollection.DeletedItems.Count > 0)
					{
						//DataRepository.DscProvider.Save(transactionManager, entity.DscCollection);
						
						deepHandles.Add("DscCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Dsc >) DataRepository.DscProvider.DeepSave,
							new object[] { transactionManager, entity.DscCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<Storm>
				if (CanDeepSave(entity.StormCollection, "List<Storm>|StormCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Storm child in entity.StormCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.StormCollection.Count > 0 || entity.StormCollection.DeletedItems.Count > 0)
					{
						//DataRepository.StormProvider.Save(transactionManager, entity.StormCollection);
						
						deepHandles.Add("StormCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Storm >) DataRepository.StormProvider.DeepSave,
							new object[] { transactionManager, entity.StormCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<PipeShape>
				if (CanDeepSave(entity.PipeShapeCollection, "List<PipeShape>|PipeShapeCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PipeShape child in entity.PipeShapeCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.PipeShapeCollection.Count > 0 || entity.PipeShapeCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PipeShapeProvider.Save(transactionManager, entity.PipeShapeCollection);
						
						deepHandles.Add("PipeShapeCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PipeShape >) DataRepository.PipeShapeProvider.DeepSave,
							new object[] { transactionManager, entity.PipeShapeCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<Orifice>
				if (CanDeepSave(entity.OrificeCollection, "List<Orifice>|OrificeCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Orifice child in entity.OrificeCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.OrificeCollection.Count > 0 || entity.OrificeCollection.DeletedItems.Count > 0)
					{
						//DataRepository.OrificeProvider.Save(transactionManager, entity.OrificeCollection);
						
						deepHandles.Add("OrificeCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Orifice >) DataRepository.OrificeProvider.DeepSave,
							new object[] { transactionManager, entity.OrificeCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<StreetTarget>
				if (CanDeepSave(entity.StreetTargetCollection, "List<StreetTarget>|StreetTargetCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(StreetTarget child in entity.StreetTargetCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.StreetTargetCollection.Count > 0 || entity.StreetTargetCollection.DeletedItems.Count > 0)
					{
						//DataRepository.StreetTargetProvider.Save(transactionManager, entity.StreetTargetCollection);
						
						deepHandles.Add("StreetTargetCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< StreetTarget >) DataRepository.StreetTargetProvider.DeepSave,
							new object[] { transactionManager, entity.StreetTargetCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<PipeShapeDatum>
				if (CanDeepSave(entity.PipeShapeDatumCollection, "List<PipeShapeDatum>|PipeShapeDatumCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PipeShapeDatum child in entity.PipeShapeDatumCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.PipeShapeDatumCollection.Count > 0 || entity.PipeShapeDatumCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PipeShapeDatumProvider.Save(transactionManager, entity.PipeShapeDatumCollection);
						
						deepHandles.Add("PipeShapeDatumCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PipeShapeDatum >) DataRepository.PipeShapeDatumProvider.DeepSave,
							new object[] { transactionManager, entity.PipeShapeDatumCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<SanPattern>
				if (CanDeepSave(entity.SanPatternCollection, "List<SanPattern>|SanPatternCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(SanPattern child in entity.SanPatternCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.SanPatternCollection.Count > 0 || entity.SanPatternCollection.DeletedItems.Count > 0)
					{
						//DataRepository.SanPatternProvider.Save(transactionManager, entity.SanPatternCollection);
						
						deepHandles.Add("SanPatternCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< SanPattern >) DataRepository.SanPatternProvider.DeepSave,
							new object[] { transactionManager, entity.SanPatternCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<Weir>
				if (CanDeepSave(entity.WeirCollection, "List<Weir>|WeirCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Weir child in entity.WeirCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.WeirCollection.Count > 0 || entity.WeirCollection.DeletedItems.Count > 0)
					{
						//DataRepository.WeirProvider.Save(transactionManager, entity.WeirCollection);
						
						deepHandles.Add("WeirCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Weir >) DataRepository.WeirProvider.DeepSave,
							new object[] { transactionManager, entity.WeirCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<SpecialLink>
				if (CanDeepSave(entity.SpecialLinkCollection, "List<SpecialLink>|SpecialLinkCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(SpecialLink child in entity.SpecialLinkCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.SpecialLinkCollection.Count > 0 || entity.SpecialLinkCollection.DeletedItems.Count > 0)
					{
						//DataRepository.SpecialLinkProvider.Save(transactionManager, entity.SpecialLinkCollection);
						
						deepHandles.Add("SpecialLinkCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< SpecialLink >) DataRepository.SpecialLinkProvider.DeepSave,
							new object[] { transactionManager, entity.SpecialLinkCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<SpecialLinkDatum>
				if (CanDeepSave(entity.SpecialLinkDatumCollection, "List<SpecialLinkDatum>|SpecialLinkDatumCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(SpecialLinkDatum child in entity.SpecialLinkDatumCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.SpecialLinkDatumCollection.Count > 0 || entity.SpecialLinkDatumCollection.DeletedItems.Count > 0)
					{
						//DataRepository.SpecialLinkDatumProvider.Save(transactionManager, entity.SpecialLinkDatumCollection);
						
						deepHandles.Add("SpecialLinkDatumCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< SpecialLinkDatum >) DataRepository.SpecialLinkDatumProvider.DeepSave,
							new object[] { transactionManager, entity.SpecialLinkDatumCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<PipeConflict>
				if (CanDeepSave(entity.PipeConflictCollection, "List<PipeConflict>|PipeConflictCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PipeConflict child in entity.PipeConflictCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.PipeConflictCollection.Count > 0 || entity.PipeConflictCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PipeConflictProvider.Save(transactionManager, entity.PipeConflictCollection);
						
						deepHandles.Add("PipeConflictCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PipeConflict >) DataRepository.PipeConflictProvider.DeepSave,
							new object[] { transactionManager, entity.PipeConflictCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<Link>
				if (CanDeepSave(entity.LinkCollection, "List<Link>|LinkCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Link child in entity.LinkCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.LinkCollection.Count > 0 || entity.LinkCollection.DeletedItems.Count > 0)
					{
						//DataRepository.LinkProvider.Save(transactionManager, entity.LinkCollection);
						
						deepHandles.Add("LinkCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Link >) DataRepository.LinkProvider.DeepSave,
							new object[] { transactionManager, entity.LinkCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<IcNodeRedirector>
				if (CanDeepSave(entity.IcNodeRedirectorCollection, "List<IcNodeRedirector>|IcNodeRedirectorCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(IcNodeRedirector child in entity.IcNodeRedirectorCollection)
					{
						if(child.StatusSource != null)
						{
							child.Status = child.StatusSource.StatusId;
						}
						else
						{
							child.Status = entity.StatusId;
						}

					}

					if (entity.IcNodeRedirectorCollection.Count > 0 || entity.IcNodeRedirectorCollection.DeletedItems.Count > 0)
					{
						//DataRepository.IcNodeRedirectorProvider.Save(transactionManager, entity.IcNodeRedirectorCollection);
						
						deepHandles.Add("IcNodeRedirectorCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< IcNodeRedirector >) DataRepository.IcNodeRedirectorProvider.DeepSave,
							new object[] { transactionManager, entity.IcNodeRedirectorCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region StatusChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>BesAsm.MasterData.Entities.Status</c>
	///</summary>
	public enum StatusChildEntityTypes
	{

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for RoofTargetCollection
		///</summary>
		[ChildEntityType(typeof(TList<RoofTarget>))]
		RoofTargetCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for CrossSectionDatumCollection
		///</summary>
		[ChildEntityType(typeof(TList<CrossSectionDatum>))]
		CrossSectionDatumCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for PumpCurveCollection
		///</summary>
		[ChildEntityType(typeof(TList<PumpCurve>))]
		PumpCurveCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for SscCollection
		///</summary>
		[ChildEntityType(typeof(TList<Ssc>))]
		SscCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for ParkingTargetCollection
		///</summary>
		[ChildEntityType(typeof(TList<ParkingTarget>))]
		ParkingTargetCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for FixedFloorElevationCollection
		///</summary>
		[ChildEntityType(typeof(TList<FixedFloorElevation>))]
		FixedFloorElevationCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for NodeCollection
		///</summary>
		[ChildEntityType(typeof(TList<Node>))]
		NodeCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for CrossSectionCollection
		///</summary>
		[ChildEntityType(typeof(TList<CrossSection>))]
		CrossSectionCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for AsmZoningCollection
		///</summary>
		[ChildEntityType(typeof(TList<AsmZoning>))]
		AsmZoningCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for PumpCollection
		///</summary>
		[ChildEntityType(typeof(TList<Pump>))]
		PumpCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for DscCollection
		///</summary>
		[ChildEntityType(typeof(TList<Dsc>))]
		DscCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for StormCollection
		///</summary>
		[ChildEntityType(typeof(TList<Storm>))]
		StormCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for PipeShapeCollection
		///</summary>
		[ChildEntityType(typeof(TList<PipeShape>))]
		PipeShapeCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for OrificeCollection
		///</summary>
		[ChildEntityType(typeof(TList<Orifice>))]
		OrificeCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for StreetTargetCollection
		///</summary>
		[ChildEntityType(typeof(TList<StreetTarget>))]
		StreetTargetCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for PipeShapeDatumCollection
		///</summary>
		[ChildEntityType(typeof(TList<PipeShapeDatum>))]
		PipeShapeDatumCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for SanPatternCollection
		///</summary>
		[ChildEntityType(typeof(TList<SanPattern>))]
		SanPatternCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for WeirCollection
		///</summary>
		[ChildEntityType(typeof(TList<Weir>))]
		WeirCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for SpecialLinkCollection
		///</summary>
		[ChildEntityType(typeof(TList<SpecialLink>))]
		SpecialLinkCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for SpecialLinkDatumCollection
		///</summary>
		[ChildEntityType(typeof(TList<SpecialLinkDatum>))]
		SpecialLinkDatumCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for PipeConflictCollection
		///</summary>
		[ChildEntityType(typeof(TList<PipeConflict>))]
		PipeConflictCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for LinkCollection
		///</summary>
		[ChildEntityType(typeof(TList<Link>))]
		LinkCollection,

		///<summary>
		/// Collection of <c>Status</c> as OneToMany for IcNodeRedirectorCollection
		///</summary>
		[ChildEntityType(typeof(TList<IcNodeRedirector>))]
		IcNodeRedirectorCollection,
	}
	
	#endregion StatusChildEntityTypes
	
	#region StatusFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;StatusColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Status"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class StatusFilterBuilder : SqlFilterBuilder<StatusColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the StatusFilterBuilder class.
		/// </summary>
		public StatusFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the StatusFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public StatusFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the StatusFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public StatusFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion StatusFilterBuilder
	
	#region StatusParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;StatusColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Status"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class StatusParameterBuilder : ParameterizedSqlFilterBuilder<StatusColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the StatusParameterBuilder class.
		/// </summary>
		public StatusParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the StatusParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public StatusParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the StatusParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public StatusParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion StatusParameterBuilder
	
	#region StatusSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;StatusColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Status"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class StatusSortBuilder : SqlSortBuilder<StatusColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the StatusSqlSortBuilder class.
		/// </summary>
		public StatusSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion StatusSortBuilder
	
} // end namespace
